package cuit.game.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jakarta.persistence.*;

@Entity
@Table(name = "t_team")
public class Team extends BaseEntity {

    @Column(name = "teamname")
    private String teamname;

    @Column(name = "content")
    private String content;
    
    @Column(name = "body")
    private long body = 0;
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name = "contest_id", referencedColumnName = "id")
    private Contest contest;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},fetch=FetchType.EAGER)
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    private User user;
  
    @OneToMany(mappedBy = "team", cascade = {CascadeType.ALL}, orphanRemoval = true)
    private List<Application> applications = new ArrayList<Application>();
    
    public Team() {
    }  
    
    @Override
	public long getId() {
		// TODO Auto-generated method stub
		return super.getId();
	}

	@Override
	public void setId(long id) {
		// TODO Auto-generated method stub
		super.setId(id);
	}

    // getter 和 setter 方法
    public List<Application> getApplications() {
        return applications;
    }

    public void setApplications(List<Application> applications) {
        if (applications == null || applications.isEmpty()) {
            this.applications = new ArrayList<>();
        } else if (this.applications == null || applications.size() != 0) {
            this.applications = new ArrayList<>();
            this.applications.addAll(applications);
        } else {
            this.applications.clear();
            this.applications.addAll(applications);
        }
    }

	public String getTeamname() {
		return teamname;
	}

	public void setTeamname(String teamname) {
		this.teamname = teamname;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public long getBody() {
		return body;
	}

	public void setBody(long body) {
		this.body = body;
	}

	public Contest getContest() {
		return contest;
	}

	public void setContest(Contest contest) {
		this.contest = contest;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		return "Team [teamname=" + teamname + ", content=" + content + ", body=" + body + ", contest=" + contest
				+ ", user=" + user + ", applications=" + applications + "]";
	}

	@Override
	public Date getCreateTime() {
		// TODO Auto-generated method stub
		return super.getCreateTime();
	}
    
    
    

}
